﻿using SuporeSliplampApp.Models;
using SuporeSliplampApp.Util;
using SuporeSliplampApp.ViewModels;
using SuporeSliplampApp.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuporeSliplampApp.Control
{
    /// <summary>
    /// ScrollControl.xaml 的交互逻辑
    /// </summary>
    public partial class ScrollControl : UserControl
    {
        public static event EventHandler<ListControlModel> scrollDelegate;
        public static event EventHandler<VideoModel> videoDelegate;

        private double selectedMultiplier;
        private int osodindex;

        public bool IsMyChecked
        {
            get { return (bool)GetValue(IsMyCheckedProperty); }
            set
            {
                SetValue(IsMyCheckedProperty, value);
                OnIsMyCheckedChanged();
            }
        }

        // Using a DependencyProperty as the backing store for IsMyChecked.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsMyCheckedProperty =
            DependencyProperty.Register("IsMyChecked", typeof(bool), typeof(ScrollControl), new PropertyMetadata(false, new PropertyChangedCallback(OnMyPropertyChanged)));

        private static void OnMyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckBox c = d as CheckBox;

        }

        public string MyPicPath
        {
            get { return (string)GetValue(MyPicPathProperty); }
            set { SetValue(MyPicPathProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MyPicPath.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MyPicPathProperty =
            DependencyProperty.Register("MyPicPath", typeof(string), typeof(ScrollControl), new PropertyMetadata(null));




        public ScrollControl()
        {
            InitializeComponent();
            var model = new ScrollControlViewModel();
            DataContext = model;
            CamaraView.openImageDelegate += CamaraView_openImageDelegate;

        }

        private void CamaraView_openImageDelegate(object sender, string e)
        {
            throw new NotImplementedException();
        }

        private void But_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {

        }

        private void confirmBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void cancelBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void StackPanel_MouseDown_1(object sender, MouseButtonEventArgs e)
        {
            // MessageBox.Show("test");
            var st = sender as StackPanel;
            ListControlModel dt = st.DataContext as ListControlModel;
            VideoModel video = st.DataContext as VideoModel;
            

            if (dt == null)
            {
                dt.Multiplier = selectedMultiplier;
                dt.osodIndex = osodindex;

                videoDelegate?.Invoke(this,video);

                //VideoPlayerWindow videoPlayerWindow = new VideoPlayerWindow(video.VideoPath);
                //videoPlayerWindow.Left = Common.picpostion.X + 8;
                //videoPlayerWindow.Top = Common.picpostion.Y + 218;
                //videoPlayerWindow.ShowDialog();
            }
            else
            {
                MyPicPath = dt.ImgPath;
                scrollDelegate?.Invoke(this, dt);
            }



        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if (myCheckBox.IsChecked == false)
            {
                IsMyChecked = false;
            }
            else
            {
                IsMyChecked = true;

            }

        }


        public event EventHandler<bool> IsMyCheckedChanged;

        private void OnIsMyCheckedChanged()
        {
            IsMyCheckedChanged?.Invoke(this, IsMyChecked);
        }


    }
}

